package com.lcy.reggie.controller;

/**
 * ======刘春春大帅逼======
 * ******java学习之旅******
 */

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lcy.reggie.common.Result;
import com.lcy.reggie.dto.SetmealDto;
import com.lcy.reggie.entity.Setmeal;
import com.lcy.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  套餐管理
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 添加套餐
     */
    @PostMapping
    public Result<String> saveSetmeal(@RequestBody SetmealDto setmealDto){
        return setmealService.saveSetmeal(setmealDto);
    }


    /**
     *  分页查询
     */
    @GetMapping("/page")
    public Result<Page> pageResult(Integer page,Integer pageSize,String name){
        return setmealService.pageResult(page,pageSize,name);
    }


    /**
     * 修改套餐时的回显
     */
    @GetMapping("/{id}")
    public Result<SetmealDto> select(@PathVariable Long id){
        return setmealService.select(id);
    }

    /**
     *  修改套餐
     */
    @PutMapping
    public Result<String> updateSetmeal(@RequestBody SetmealDto setmealDto){
        return setmealService.updateSetmeal(setmealDto);
    }

    /**
     *  删除、批量删除
     */
    @DeleteMapping()
    public Result<String> deleteByIds(@RequestParam("ids") List<Long> ids){
        return setmealService.updateByIds(ids);
    }

    /**
     *  批量修改售卖状态
     */
    @PostMapping("/status/{status}")
    public Result<String> updateStatus(@PathVariable Integer status,@RequestParam("ids")List<Long> ids){
        return setmealService.updateStatus(status,ids);
    }

    /**
     *  手机端展示套餐各信息
     */
    @GetMapping("/list")
    public Result<List<Setmeal>> listSetmeal(Setmeal setmeal){
        return setmealService.listSetmeal(setmeal);
    }
}
